<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="com.sz.common.ICommonDAO" %>
<%@page import="java.net.URLDecoder"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//String style1 = "width: 200px;text-align:right";
//String style2 = "text-align:left;width: 250px";


String style1 = "width: 80;text-align:right;font-size: 12px;";
String style2 = "width: 120px";
String style3 = "color: red;text-align:left;";
String style4 = "font-size: 12px;";

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);

ICommonDAO dao = (ICommonDAO) context.getBean("CommonDAO");
String PrimaryBusiness_ID = request.getParameter("business_id");
String business_name = request.getParameter("business_name");
if(business_name != null) {
	business_name = URLDecoder.decode(business_name, "UTF-8");
}
String Select_Group_Sql = "select group_id from business where business_id = " + PrimaryBusiness_ID;
List list_BusinessGroup = dao.queryForList(Select_Group_Sql);


String Group_ID = null;
if (list_BusinessGroup.size() > 0)
{
  Map map = (Map)list_BusinessGroup.get(0);
  Group_ID = map.get("GROUP_ID").toString();
}


String url = "page/ChooseBusinessRecommendAs.jsp?business_id=" + PrimaryBusiness_ID;
url += "&Group_id=" + Group_ID;
String src = url;
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	    <link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">


		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="addTicket">

		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
    	</style>
	</head>
	
	<body>
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		<table width="100%" height="20px" border="0" cellpadding="0" cellspacing="0">
	  	 
	  	<tr>
		  	<td class="title0">商家推荐维护<br></td>  	
	  	</tr>
	  	</table>
	  	
	
		<table width="100%" height=40px border="0" cellpadding="0" cellspacing="0" >
		<tr>
  			<td style="<%=style1%>">商家ID&nbsp;<br></td>		
		  	<td>
		  		<input  type="text" id="business_id" name="business_id"  value="<%=PrimaryBusiness_ID%>"  readonly="readonly"  style="<%=style2%>">
		  	</td>	
  			<td style="<%=style1%>">商家名称&nbsp;</td>
		  	<td>
		  		<input  type="text" id="business_name" name="business_name"  value="<%=business_name%>"  readonly="readonly"  style="<%=style2%>">
		  	</td>	
			<td class="title0">
            	<input type="button" id="btn" name="btn" value="查询已推荐商家" onclick="onClickQueryRecommend()">
            </td>
	  	</tr>
			  
	  	</table>
	  	  

	  	<div id="table_div" style= "width: 100%"></div>
		<div id="pager"></div>		
		<script type="text/javascript">
		
		var numPerPage = 5; //每页行数
		var paramValue = ""; //形如  "{STATUS:'1', CREATE_MANAGER:'1'}"
		var delparamValue = "";
		var methodCount = "queryRecommendCount";
		var methodPage = "queryRecommendPage";
		
		var table = new TableView('table_div');
		table.header = {
			BUSINESS_RECOMMEND_ID	: '商家ID',
				BUSINESS_NAME			: '商家名称',
				BUSINESS_ADDRESS		: '商家地址',
				BUSINESS_TEL			: '预定电话',
				CHECK_STATUS_STR  		: '签约状态',
				WORK_STATUS_STR     	: '营业状态',
			    PREORDER_FLAG_STR   	: '预定状态',
			    	DETAIL				: '详细信息',
				OPREATE_BUSINESS    	: '操作'
		};		
		table.customDefine = {
				BUSINESS_RECOMMEND_ID	: '',
				BUSINESS_NAME		    : '',
				BUSINESS_ADDRESS		: '',
				BUSINESS_TEL		    : '',
				CHECK_STATUS_STR		: '',
				WORK_STATUS_STR     	: '',
			    PREORDER_FLAG_STR   	: '',
			    	DETAIL				: '',
				OPREATE_BUSINESS    	: ''
		};
				
		table.dataKey = 'BUSINESS_RECOMMEND_ID';
		table.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.pager.size = numPerPage;
		table.display.multiple = false;
		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryRecommend(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "BusinessRecommendBMO.queryRecommend",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});

  			return true;
  			
  		}

  		function onPagerClick(pageNO) {
  			queryRecommend(pageNO, "FLASE");
  		}
  		
  		//刷新当前页
  		function refreshCurrentPage() {
  			queryRecommend(pager.index, "FLASE");
  		}

  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   for(var i = 0; i < array.length; ++i) {
		   		//形如：<a href="javascript:" onclick="about()">modal</a>	
		   		var url = "<a href=\"javascript:\" onclick=\"onBusinessDetail('";
		   		url += array[i].BUSINESS_RECOMMEND_ID;
		   		url += "')\">详细信息</a>";
		   		array[i].DETAIL = url;
		   			   		
		        url = "<input type=\"button\" value=\"删除\" onclick=\"OnDelRecommend('";
		   		url += array[i].BUSINESS_RECOMMEND_ID;
		   		url += "')\" />";
		   	    array[i].OPREATE_BUSINESS = url; 
		   		
		   		
   		  		//签约状态转义
	   		    if(array[i].CHECK_STATUS ==1) array[i].CHECK_STATUS_STR = "已签约";
               else if(array[i].CHECK_STATUS ==0) array[i].CHECK_STATUS_STR = "未签约";
               else array[i].CHECK_STATUS_STR = "未知";
               
               //预约状态转义
               if(array[i].PREORDER_FLAG ==1) array[i].PREORDER_FLAG_STR = "可预定";
               else if(array[i].PREORDER_FLAG ==0) array[i].PREORDER_FLAG_STR = "不可预定";
               else array[i].PREORDER_FLAG_STR = "未知";
               
               //营业状态转义	  
               if(array[i].WORK_STATUS ==1) array[i].WORK_STATUS_STR = "正常";
               else if(array[i].WORK_STATUS ==2) array[i].WORK_STATUS_STR = "暂停营业";
                else if(array[i].WORK_STATUS ==0) array[i].WORK_STATUS_STR = "关闭";
               else array[i].WORK_STATUS_STR = "未知";
               
		   }
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		
  		function onClickQueryRecommend() 
  		{		
  			var tmp;
		
			
 			paramValue = "{";
			
  			tmp = document.getElementById("business_id").value;
  			paramValue += "  BUSINESS_ID:'" + tmp;
			paramValue += "'";
			paramValue += ",";
			
  			paramValue += "}";
 				
  	  		pager.index = 1;
  	  		queryRecommend(1, true);
			

  		}

  		function onBusinessDetail(business_id) {
   			var url = "<%=path%>";
  			url += "/page/viewBusiness.jsp?business_id=" + business_id;
  			var param = "status:no;scroll:yes;dialogWidth:1024px;dialogHeight:600px";
			window.showModalDialog(url, window, param); 			
  		}
  		
 		function showMsg(data) {
  	  		alert(data);
 		}
 		
 		
 		function OnDelRecommend(business_id) 
 		{
			var date = {
 	  			OPERATE_TYPE	: "DEL",
 	  			BUSINESS_ID 	: business_id
 	  	    };
 	  	    
 	  		$.ajax({
			type: "POST",
			url: "delBusinessRecommend.exec",
			//data: {id:'123'},
			data: date,
			datatype:"json",
			success: del_success,
			error: show_error
 	  		});	
 		}

        function del_success(data)
        {
	        alert(data);
	        refreshCurrentPage();
        }
 		
	</script>
		<iframe frameborder="0" src="<%=src%>" width="100%" height="100%" style="z-index:9"> 
	  	</iframe>  
	</body>
</html>
